package com.chen.manager.service.impl;

import com.chen.manager.mapper.SysRoleMapper;
import com.chen.manager.service.SysRoleService;
import com.chen.model.dto.system.SysRoleDto;
import com.chen.model.entity.system.SysRole;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author cgj
 * @date 2/12/25 8:40 AM
 */
@Transactional
@Service
public class SysRoleServiceImpl implements SysRoleService {
    @Autowired
    private SysRoleMapper sysRoleMapper;
    @Override
    public PageInfo<SysRole> findAllByPage(SysRoleDto sysRoleDto, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<SysRole> sysRoleList =sysRoleMapper.selectAllByPage(sysRoleDto);
        
        return new PageInfo<>(sysRoleList);
    }

    @Override
    public Integer savaRole(SysRole sysRole) {

        return sysRoleMapper.insertSysRole(sysRole);
    }

    @Override
    public void edit(SysRole sysRole) {
        sysRoleMapper.updateRole(sysRole);
    }

    @Override
    public void removeSysRole(Integer id) {
        sysRoleMapper.deleteSysRoleById(id);
    }

    @Override
    @Transactional(readOnly = true)
    public List<SysRole> selectAll() {
        List<SysRole> list=sysRoleMapper.selectAll();
        return list;
    }
}
